package cn.com.huzo.repository.tech.impl;

import cn.com.huzo.model.entities.tech.PieceYardageLinesColourSchemaEntity;
import cn.com.huzo.repository.tech.PieceYardageLinesColourSchemaRepository;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.stereotype.Repository;

/**
 * 成品色数据对象实现。
 *
 * @author 吴旭
 */
@Repository("PieceYardageLinesColourSchemaRepository")
public class PieceYardageLinesColourSchemaRepositoryImpl extends GenericRepositoryImpl<PieceYardageLinesColourSchemaEntity, String>
        implements PieceYardageLinesColourSchemaRepository {

    private final String namespace = "cn.com.huzo.repository.tech.PieceYardageLinesColourSchemaRepository";

    /**
     * 构造函数,设置the entity to UcLinesRepositoryImpl.class.
     */
    public PieceYardageLinesColourSchemaRepositoryImpl() {
        super(PieceYardageLinesColourSchemaEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<PieceYardageLinesColourSchemaEntity> fetchByHeaderKey(Long headerKey) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByHeaderKey"), headerKey);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insert(List<PieceYardageLinesColourSchemaEntity> itemList) {
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), itemList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertLinesFromClipboard(Long headerId, String copiedLinesId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("CopiedLinesId", copiedLinesId);
        
        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertLinesFromClipboard"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer importLinesFromOtherBom(Long headerId, Long importedBomHeaderId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("ImportedBomHeaderId", importedBomHeaderId);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "importLinesFromOtherBom"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer changeMaterialColour(Long headerId, String bomLinesId, String materialColourName, Long productColourId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("ParentLinesId", bomLinesId);
        criterion.put("MaterialColourName", materialColourName);
        criterion.put("ProductColourId", productColourId);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "changeMaterialColour"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateParentLinesIdForImportedLines(Long headerId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateParentLinesIdForImportedLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer deleteByParentLinesKey(String parentLinesKey) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "deleteByParentLinesKey"), parentLinesKey);
    }
}
